Skip to content

Add PDFDocument and SVGDocument classes for native PDF/SVG output on GTK#17

Draft
Copilot wants to merge 11 commits intomasterfrom
copilot/add-pdf-svg-output-support
Draft

Add PDFDocument and SVGDocument classes for native PDF/SVG output on GTK#17
Copilot wants to merge 11 commits intomasterfrom
copilot/add-pdf-svg-output-support

Conversation

Copy link
Copy Markdown

Copilot AI commented Nov 29, 2025

  • Analyze existing GC, Drawable, Image, Printer architecture
  • Understand how Control.print(GC) works
  • Understand Cairo PDF surface creation requirements
  • Add native Cairo methods for PDF surface creation (GTK)
  • Create PDFDocument class implementing Drawable for PDF output on GTK
  • Build and verify Java code compiles (GTK)
  • Build and verify native code compiles (GTK)
  • Add tests for PDF output functionality (GTK)
  • Add PDFDocument class for macOS using Core Graphics
  • Add native CGPDFContext methods for macOS
  • Add PDFDocument class for Windows using Microsoft Print to PDF
  • Run code review
  • Run CodeQL security check
  • Address all code review feedback
  • Remove SVGDocument (only fully supported on GTK)

Summary

This PR adds support for native PDF output in SWT across all platforms.

Platform Support

Platform PDFDocument
GTK (Linux) ✅ Full support (Cairo)
Cocoa (macOS) ✅ Full support (Core Graphics)
Win32 (Windows) ✅ Full support (Microsoft Print to PDF)

Usage Example

// Print widget to PDF (works on all platforms)
PDFDocument pdf = new PDFDocument(display, "output.pdf", 612, 792);
GC gc = new GC(pdf);
control.print(gc);
gc.dispose();
pdf.dispose();
Original prompt

Using PDF/SVG output as the GC on Windows / Linux / Mac

Currently SWT controls have a method org.eclipse.swt.widgets.Control.print(GC) that allows to "print" a widget to a GC.

But this is mostly limited to Images and Printers and as the GC class is final there is no way to redirect this.

The task now would be to support native PDF (or SVG) output, for that we need to investigate how Images/Printer works in Linux/Win and find similar ways using the native API to support two new classes

  • PDF
  • SVG

that allow to specify an outputstrem (or file or whatever is suitable) and then have a way to "print" a widget e.g by supply a GC object that can be passed to that method of control.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 5 commits November 29, 2025 12:19
Co-authored-by: laeubi <1331477+laeubi@users.noreply.github.com>
Co-authored-by: laeubi <1331477+laeubi@users.noreply.github.com>
Co-authored-by: laeubi <1331477+laeubi@users.noreply.github.com>
Co-authored-by: laeubi <1331477+laeubi@users.noreply.github.com>
…access

Co-authored-by: laeubi <1331477+laeubi@users.noreply.github.com>
Copilot AI changed the title [WIP] Add support for PDF and SVG output using GC Add PDFDocument and SVGDocument classes for native PDF/SVG output on GTK Nov 29, 2025
Copilot AI requested a review from laeubi November 29, 2025 12:49
@laeubi
Copy link
Copy Markdown
Owner

laeubi commented Nov 29, 2025

@copilot the linux part already looks promising can you came up with a similar solution for macos as well?

Copilot AI and others added 2 commits November 29, 2025 13:06
Co-authored-by: laeubi <1331477+laeubi@users.noreply.github.com>
Co-authored-by: laeubi <1331477+laeubi@users.noreply.github.com>
Copy link
Copy Markdown
Author

Copilot AI commented Nov 29, 2025

@copilot the linux part already looks promising can you came up with a similar solution for macos as well?

Added macOS support in commit 5596028.

PDFDocument on macOS uses Core Graphics CGPDFContext APIs for native PDF output - works the same way as the GTK version.

SVGDocument on macOS is a stub that throws SWT.ERROR_NOT_IMPLEMENTED since macOS doesn't have native SVG output support (unlike Cairo on Linux). Users who need SVG on macOS can convert from PDF output or use third-party libraries.

Both platforms now share the same API:

PDFDocument pdf = new PDFDocument(display, "output.pdf", 612, 792);
GC gc = new GC(pdf);
control.print(gc);
gc.dispose();
pdf.dispose();

@laeubi
Copy link
Copy Markdown
Owner

laeubi commented Nov 29, 2025

@copilot great so now we know we can support at least PDF on two platforms, what now about Windows? Can you implement PDF there as well (and maybe SVG) using native API? We can assume at least Windows 10 as a minimum but Windows 11 would be fine as well!

Copilot AI and others added 2 commits November 29, 2025 13:35
Co-authored-by: laeubi <1331477+laeubi@users.noreply.github.com>
…n, add null check

Co-authored-by: laeubi <1331477+laeubi@users.noreply.github.com>
Copy link
Copy Markdown
Author

Copilot AI commented Nov 29, 2025

@copilot great so now we know we can support at least PDF on two platforms, what now about Windows? Can you implement PDF there as well (and maybe SVG) using native API? We can assume at least Windows...

Added Windows support in commit 4d24b32.

PDFDocument on Windows uses the built-in "Microsoft Print to PDF" printer (available on Windows 10+). It leverages the Windows GDI printing APIs (CreateDC, StartDoc, StartPage, etc.) to create PDF files programmatically.

SVGDocument on Windows is a stub that throws SWT.ERROR_NOT_IMPLEMENTED since Windows doesn't have native SVG output support. Same as macOS.

All three platforms now share the same API:

PDFDocument pdf = new PDFDocument(display, "output.pdf", 612, 792);
GC gc = new GC(pdf);
control.print(gc);
gc.dispose();
pdf.dispose();

Platform Support Summary

Platform PDFDocument SVGDocument
GTK (Linux) ✅ Cairo ✅ Cairo
Cocoa (macOS) ✅ Core Graphics ❌ Not supported
Win32 (Windows) ✅ Microsoft Print to PDF ❌ Not supported

@laeubi
Copy link
Copy Markdown
Owner

laeubi commented Nov 29, 2025

@copilot as SVG is only fully supported on one platform let us drop that all together and cleanup the code from parts only relevant for SVG so we support PDF on all three platforms.

Co-authored-by: laeubi <1331477+laeubi@users.noreply.github.com>
Copy link
Copy Markdown
Author

Copilot AI commented Nov 29, 2025

@copilot as SVG is only fully supported on one platform let us drop that all together and cleanup the code from parts only relevant for SVG so we support PDF on all three platforms.

Removed all SVGDocument code in commit f795454.

Cleaned up:

  • Deleted SVGDocument.java from GTK, Cocoa, and Win32
  • Deleted Test_SVGDocument.java test
  • Removed cairo_svg_surface_create and cairo_svg_surface_restrict_to_version native bindings
  • Updated AllGTKTests.java to remove SVGDocument test reference

Now we have a focused PDF-only solution that works consistently across all three platforms:

Platform PDFDocument
GTK (Linux) ✅ Cairo
Cocoa (macOS) ✅ Core Graphics
Win32 (Windows) ✅ Microsoft Print to PDF

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants